<?php

namespace Drupal\shusy_store\Entity;

use Drupal\shusy_store\ViewsController\Traits\ShusyStoreSexTrait;
use Drupal\shusy_store\ViewsController\Traits\ShusyStoreStatusTrait;
use Drupal\shusy_store\ViewsController\Traits\ShusyStoreTypeTrait;
use Entity;

class ShusyStore extends Entity {

  public $id;

  public $vid;

  public $uid;

  public $op_uid;

  public $created;

  public $changed;

  public $is_new_revision;

  public $type = 0;

  public $sex;

  public $name;

  public $phone;

  public $identity;

  public $level_1;

  public $level_2;

  public $city_id;

  public $store_name;

  public $store_address;

  public $coordinate = 5;

  public $longitude;

  public $latitude;

  public $bank_no;

  public $bank_name;

  public $bank_file;

  public $identity_face;

  public $logo;

  public $business;

  public $open;

  public $note = '';

  public $status = 0;

  public $food_trade_license;

  public $charge = 0.1;

  use ShusyStoreSexTrait;
  use ShusyStoreStatusTrait;
  use ShusyStoreTypeTrait;

  function __construct($values = []) {
    $this->is_new_revision = TRUE;
    parent::__construct($values, 'shusy_store');
  }

  public function save() {
    $this->changed = REQUEST_TIME;
    if (empty($this->created)) {
      $this->created = REQUEST_TIME;
    }

    $this->op_uid = $GLOBALS['user']->uid;
    if (empty($this->uid)) {
      $this->uid = $GLOBALS['user']->uid;
    }

    return parent::save();
  }

  function getLongitude() {
    return $this->longitude ? $this->longitude : NULL;
  }

  function getLatitude() {
    return $this->latitude ? $this->latitude : NULL;
  }

  public function label() {
    return "{$this->store_name} ({$this->id}) [{$this->name}]";
  }

}
